<?php

namespace app\common\behavior;


class SmsBehavior
{
    const url ="https://dx.ipyy.net/sms.aspx";

    public function run(&$params)
    {
        if($params['event']=='mobilelogin'){
            $content = "【河北省佰佳医学检验实验室有限公司】您本次申请的验证码是{$params['code']}，请勿泄露他人！如非本人操作请忽略。";
        }
        $result = $this->sendVerifyCode($params['mobile'], $content);
        return $result;
        
    }

    public function sendVerifyCode($mobile, $content)
    {
        $body=array(
    				'action'=>'send',
    				'userid'=>'',
    				'account'=>'bjcc001',
    				'password'=>'@#qcw100com',
    				'mobile'=>$mobile,
    				'extno'=>'',
    				'content'=>$content,
    				'sendtime'=>''    				
    		);

    		$ch=curl_init();
    		curl_setopt($ch, CURLOPT_URL, self::url);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    		$result = curl_exec($ch);

    		curl_close($ch);
    		$data = simplexml_load_string($result);
			if($data->returnstatus == 'Faild'){
				\think\Log::record('发送验证码失败：'.$data['message'].';rowData:'.json_encode($data),'error');
				return false;
			}else{
				return true;
			}

    }
}